package com.develop.mybluetooth.fragment

import android.bluetooth.BluetoothGattService
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.develop.bluetoothlib.MyBluetooth
import com.develop.mybluetooth.adapter.ServicesAdapter
import com.develop.mybluetooth.databinding.FragmentBleServiceListBinding

/**
 * BLE的服务列表
 */

class BLEServiceListFragment : Fragment() {

    private var myBluetooth: MyBluetooth? = null

    private val TAG = "BLEFragment"

    private var binding : FragmentBleServiceListBinding ?= null
    private var adapter : ServicesAdapter?= null
    private var linearLayoutManager : LinearLayoutManager ?= null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        myBluetooth = MyBluetooth.getInstance()
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentBleServiceListBinding.inflate(layoutInflater)
        return binding?.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        linearLayoutManager = LinearLayoutManager(context)
        binding?.rvServices?.layoutManager = linearLayoutManager
        adapter = ServicesAdapter()
        binding?.rvServices?.adapter = adapter

    }


    fun addServices(services: List<BluetoothGattService>?){
        adapter?.submitList(services)
    }

}